package action;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Component;

import utils.UriPost;


@Component
public class FenceAction {
	
	public void  creatFence() throws IOException {
		PrintWriter out = ServletActionContext.getResponse().getWriter();
		if(radius >5000 || radius<0){
			out.print("-1");
		}else{
		valid_times = valid_times.replaceAll(":", "");
		String url = "http://api.map.baidu.com/trace/v2/fence/create";
		String parm ="ak="+ak
				  +"&service_id="+service_id
				  +"&name="+name
				  +"&creator="+creator
				  +"&monitored_persons="+monitored_persons
				  +"&observers="+observers[0]
				  +"&valid_times="+valid_times
				  +"&valid_cycle="+valid_cycle
				  +"&shape="+shape
				  +"&coord_type="+coord_type
				  +"&center="+center
				  +"&radius="+radius
				  +"&alarm_condition="+alarm_condition+"" ;
		 System.out.println(parm);
		 String creatfence = UriPost.entityCreate(url, parm);
		 System.out.println(creatfence);
		 out.print(creatfence);
		 out.flush();
		 out.close();
		}
	}

	private String ak;                    //用户的ak，授权使用
	private int service_id;               //service的唯一标识
	private String name;                  //围栏名称
	private String creator;               //围栏创建者
	private String monitored_persons;     //监控对象
	private String [] observers;          //观察者列表
	private String valid_times;           //
	private int valid_cycle;
	private String valid_date;
	private int shape;
	private int coord_type;
	private String  center;
	private double radius;
	private int alarm_condition;
	
	public String getAk() {
		return ak;
	}
	public void setAk(String ak) {
		this.ak = ak;
	}
	public int getService_id() {
		return service_id;
	}
	public void setService_id(int service_id) {
		this.service_id = service_id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getCreator() {
		return creator;
	}
	public void setCreator(String creator) {
		this.creator = creator;
	}
	public String getMonitored_persons() {
		return monitored_persons;
	}
	public void setMonitored_persons(String monitored_persons) {
		this.monitored_persons = monitored_persons;
	}
	public String[] getObservers() {
		return observers;
	}
	public void setObservers(String[] observers) {
		this.observers = observers;
	}
	public String getValid_times() {
		return valid_times;
	}
	public void setValid_times(String valid_times) {
		this.valid_times = valid_times;
	}
	public int getValid_cycle() {
		return valid_cycle;
	}
	public void setValid_cycle(int valid_cycle) {
		this.valid_cycle = valid_cycle;
	}
	public String getValid_date() {
		return valid_date;
	}
	public void setValid_date(String valid_date) {
		this.valid_date = valid_date;
	}
	public int getShape() {
		return shape;
	}
	public void setShape(int shape) {
		this.shape = shape;
	}
	public int getCoord_type() {
		return coord_type;
	}
	public void setCoord_type(int coord_type) {
		this.coord_type = coord_type;
	}

	public String getCenter() {
		return center;
	}

	public void setCenter(String center) {
		this.center = center;
	}

	public double getRadius() {
		return radius;
	}
	public void setRadius(double radius) {
		this.radius = radius;
	}
	public int getAlarm_condition() {
		return alarm_condition;
	}
	public void setAlarm_condition(int alarm_condition) {
		this.alarm_condition = alarm_condition;
	}
}
